#include <queue>
using namespace std;

struct TreeNode {
  int val;
  TreeNode *left;
  TreeNode *right;
  TreeNode()
      : val(0), left(nullptr), right(nullptr){} * TreeNode(int x)
      : val(x),
        left(nullptr), right(nullptr) {}
  TreeNode(int x, TreeNode *left, TreeNode *right)
      : val(x), left(left), right(right) {}
};

int findBottomLeftValue(TreeNode *root) {
  queue<TreeNode *> q;
  q.push(root);
  int left_value = 0;
  bool isFind = false;
  while (!q.empty()) {
    int n = q.size();
    isFind = false;
    while (n--) {
      TreeNode *node = q.front();
      if (node->left)
        q.push(node->left);
      if (node->right)
        q.push(node->right);
      if (isFind == false) {
        isFind = true;
        left_value = node->val;
      }
      q.pop();
    }
  }
  return left_value;
}